/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RegistrarPuesto.java
 *
 * Created on 28/03/2011, 09:57:01 AM
 */
package zonasoft.Vistas.Negocio;

import com.mysql.jdbc.Connection;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import zonasoft.Conceptos.Especiales.Barrio;
import zonasoft.Conceptos.Especiales.Departamentos;
import zonasoft.Conceptos.Especiales.Localidad;
import zonasoft.Conceptos.Especiales.Municipios;
import zonasoft.Conceptos.Puesto;
import zonasoft.Conceptos.Zona;
import zonasoft.Manejadores.ManejadorBaseDatos;
import zonasoft.Manejadores.ManejadorDepartamentos;
import zonasoft.Manejadores.ManejadorLugar;
import zonasoft.Manejadores.ManejadorMunicipios;
import zonasoft.Manejadores.ManejadorPuesto;
import zonasoft.Manejadores.ManejadorZona;

/**
 *
 * @author Usuario
 */
public class RegistrarPuesto extends javax.swing.JDialog {

    HashMap<String, Integer> departamentos;
    HashMap<String, Integer> municipios;
    HashMap<String, Integer> zonas;
    HashMap<String, Integer> barrio;
    HashMap<String, Integer> localidad;

    /** Creates new form RegistrarPuesto */
    public RegistrarPuesto(java.awt.Frame parent) {
        super(parent, true);
        initComponents();
        pack();
        Rectangle parentBounds = parent.getBounds();
        Dimension size = getSize();
        // Center in the parent
        int x = Math.max(0, parentBounds.x + (parentBounds.width - size.width) / 2);
        int y = Math.max(0, parentBounds.y + (parentBounds.height - size.height) / 2);
        setLocation(new Point(x, y));
        comboMunicipios.setEnabled(false);
        campoLocalidad.setText("");
        textDep.setText("Seleccione un departamento ");
//        comboLocalidad.setEnabled(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jXTaskPaneContainer1 = new org.jdesktop.swingx.JXTaskPaneContainer();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        areaDireccion = new javax.swing.JTextArea();
        jLabel11 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        campoCodigo = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        campoNombre = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        campoHombres = new javax.swing.JTextField();
        campoMujeres = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        campoTotal = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        campoMesas = new javax.swing.JTextField();
        jXPanel1 = new org.jdesktop.swingx.JXPanel();
        jLabel13 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        comboDepartamento = new javax.swing.JComboBox();
        comboZona = new javax.swing.JComboBox();
        campoLocalidad = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        ucdg = new javax.swing.JTextField();
        comboBarrio = new javax.swing.JComboBox();
        comboMunicipios = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        textDep = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        botonGuardar = new javax.swing.JButton();
        botonCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("");

        jLabel1.setFont(new java.awt.Font("Vani", 3, 18));
        jLabel1.setText("Registro Puestos de Votacion");
        jXTaskPaneContainer1.add(jLabel1);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.lightGray, java.awt.Color.lightGray, java.awt.Color.black, java.awt.Color.black), "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Lucida Bright", 3, 12))); // NOI18N

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.lightGray, java.awt.Color.lightGray, java.awt.Color.black, java.awt.Color.black), "Datos Generales", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Lucida Bright", 3, 12))); // NOI18N

        areaDireccion.setColumns(20);
        areaDireccion.setRows(5);
        jScrollPane1.setViewportView(areaDireccion);

        jLabel11.setFont(new java.awt.Font("Lucida Bright", 0, 12)); // NOI18N
        jLabel11.setText("Direccion");

        jLabel5.setFont(new java.awt.Font("Lucida Bright", 0, 12)); // NOI18N
        jLabel5.setText("Codigo");

        jLabel6.setFont(new java.awt.Font("Lucida Bright", 0, 12)); // NOI18N
        jLabel6.setText("Nombre");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(jLabel11)
                    .addComponent(jLabel5))
                .addGap(10, 10, 10)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(campoNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE)
                    .addComponent(campoCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addGap(16, 16, 16))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(campoNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.lightGray, java.awt.Color.lightGray, java.awt.Color.black, java.awt.Color.black), "Capacidad Electoral", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Lucida Bright", 3, 12))); // NOI18N

        jLabel7.setFont(new java.awt.Font("Lucida Bright", 0, 12)); // NOI18N
        jLabel7.setText("Mujeres");

        jLabel8.setFont(new java.awt.Font("Lucida Bright", 0, 12)); // NOI18N
        jLabel8.setText("Hombres");

        campoHombres.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                campoHombresKeyReleased(evt);
            }
        });

        campoMujeres.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                campoMujeresKeyReleased(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("Lucida Bright", 0, 12)); // NOI18N
        jLabel9.setText("Capacidad");

        campoTotal.setEnabled(false);

        jLabel10.setFont(new java.awt.Font("Lucida Bright", 0, 12)); // NOI18N
        jLabel10.setText("N° Mesas");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(campoTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(campoMujeres, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addGap(28, 28, 28)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(campoHombres, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
                    .addComponent(jLabel8)
                    .addComponent(jLabel10)
                    .addComponent(campoMesas, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jLabel7))
                .addGap(1, 1, 1)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoMujeres, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(campoHombres, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(22, 22, 22)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, 15, Short.MAX_VALUE)
                    .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, 15, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(campoMesas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29))
        );

        jXPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Ubicacion", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Lucida Bright", 3, 12))); // NOI18N

        jLabel13.setFont(new java.awt.Font("Lucida Bright", 0, 12)); // NOI18N
        jLabel13.setText("Localidad");

        jLabel4.setFont(new java.awt.Font("Lucida Bright", 0, 12)); // NOI18N
        jLabel4.setText("Zona de Votacion");

        jLabel2.setFont(new java.awt.Font("Lucida Bright", 0, 12)); // NOI18N
        jLabel2.setText("Departamento");

        listaraDepartamento();
        comboDepartamento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboDepartamentoActionPerformed(evt);
            }
        });

        //listaraZonas();

        campoLocalidad.setEditable(false);

        jLabel12.setFont(new java.awt.Font("Lucida Bright", 0, 12)); // NOI18N
        jLabel12.setText("Barrio");

        jLabel14.setFont(new java.awt.Font("Lucida Bright", 0, 12)); // NOI18N
        jLabel14.setText("U.C.G");

        ucdg.setEditable(false);

        listaraBarrios();
        comboBarrio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboBarrioActionPerformed(evt);
            }
        });

        listaraBarrios();
        comboMunicipios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboMunicipiosActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Lucida Bright", 0, 12)); // NOI18N
        jLabel3.setText("Municipio");

        javax.swing.GroupLayout jXPanel1Layout = new javax.swing.GroupLayout(jXPanel1);
        jXPanel1.setLayout(jXPanel1Layout);
        jXPanel1Layout.setHorizontalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jXPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(comboDepartamento, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jLabel13)
                    .addGroup(jXPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(campoLocalidad, javax.swing.GroupLayout.PREFERRED_SIZE, 217, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(comboZona, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(32, 32, 32)
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12)
                    .addComponent(jLabel3)
                    .addComponent(jLabel14))
                .addGap(18, 18, 18)
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(ucdg, javax.swing.GroupLayout.DEFAULT_SIZE, 213, Short.MAX_VALUE)
                    .addComponent(comboBarrio, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comboMunicipios, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jXPanel1Layout.setVerticalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(comboDepartamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(comboMunicipios, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(comboZona, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(comboBarrio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(campoLocalidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14)
                    .addComponent(ucdg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(24, Short.MAX_VALUE))
        );

        textDep.setBackground(new java.awt.Color(255, 255, 255));
        textDep.setFont(new java.awt.Font("Lucida Bright", 3, 12));
        textDep.setForeground(new java.awt.Color(255, 51, 51));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jXPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(218, 218, 218)
                        .addComponent(textDep, javax.swing.GroupLayout.PREFERRED_SIZE, 243, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(textDep, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jXPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.lightGray, java.awt.Color.lightGray, java.awt.Color.black, java.awt.Color.black));

        botonGuardar.setFont(new java.awt.Font("Lucida Bright", 3, 12));
        botonGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zonasoft/Vistas/iconos/Floppy-icon.png"))); // NOI18N
        botonGuardar.setText("Guardar");
        botonGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonGuardarActionPerformed(evt);
            }
        });

        botonCancelar.setFont(new java.awt.Font("Lucida Bright", 3, 12));
        botonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zonasoft/Vistas/iconos/Delete-icon.png"))); // NOI18N
        botonCancelar.setText("Cancelar");
        botonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(botonCancelar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)
                    .addComponent(botonGuardar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(botonGuardar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botonCancelar)
                .addContainerGap(16, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jXTaskPaneContainer1, javax.swing.GroupLayout.DEFAULT_SIZE, 945, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jXTaskPaneContainer1, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(144, 144, 144)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
//public boolean revision(){
//  boolean estado = false;
//                ManejadorBaseDatos manejabd = ManejadorBaseDatos.getInstancia();
//                  try {
//                    manejabd.conectar();
//                    ManejadorPuesto.con=(Connection) manejabd.getConexion();
//                  Puesto pue = new Puesto();
//                    String nombreZona=comboZona.getSelectedItem().toString();
//                    Integer idZonaSelecionada= zonas.get(nombreZona);
//                    String id = (String.valueOf( idZonaSelecionada));
//                    pun = ManejadorPuesto.getZonas()
//                    can = ManejadorCandidato.getCandidatoE(id);
//                     if (can != null){
//                          estado = true;
//                          }else{
//                             //JOptionPane.showMessageDialog(null," Esta Eleccion no Tiene Candidato Asociado", "Busqueda sin resultados",JOptionPane.INFORMATION_MESSAGE);
//                          estado = false;
//                          }
//                   } catch (Exception ex) {
//            // Logger.getLogger(ConsultaEleccion.class.getName()).log(Level.SEVERE
//                  }
//  return estado;
//}
    Puesto pu = new Puesto();
    ManejadorPuesto mp = new ManejadorPuesto();
    private void botonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCancelarActionPerformed
        // TODO add your handling code here:
        int resp = JOptionPane.showConfirmDialog(this, "Seguro que deseas cerrar la Ventana ", "Warning", JOptionPane.YES_NO_OPTION);
        if (resp == JOptionPane.YES_OPTION) {
            this.dispose();
        }
    }//GEN-LAST:event_botonCancelarActionPerformed
    String total2;

    public void suma() {
        campoTotal.setText("");
        int suma = 0;
        String n1 = (!campoMujeres.getText().isEmpty()) ? campoMujeres.getText().trim() : "-1"; // operador terniario
        String n2 = (!campoHombres.getText().isEmpty()) ? campoHombres.getText().trim() : "-1"; // operador terniario

        if (!n1.equals("-1")) {
            suma += (Integer.parseInt(n1));
        }

        if (!n2.equals("-1")) {
            suma += (Integer.parseInt(n2));
        }
        total2 = String.valueOf(suma);
        campoTotal.setText(total2);
//    if(   !campoMujeres.getText().isEmpty()){
//         int h = Integer.parseInt(campoHombres.getText());
//               int m = Integer.parseInt(campoMujeres.getText());
//               int total = h +m;
//            total2 =String.valueOf( total);
//            campoTotal.setText(total2);
//        }else{
//
//        }
    }
    private void botonGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonGuardarActionPerformed
        // TODO add your handling code here:
        ManejadorBaseDatos mb = ManejadorBaseDatos.getInstancia();
        if (campoCodigo.getText().isEmpty()) {
            JOptionPane.showMessageDialog(null, "el campo codigo del Puesto esta vacio", "Campos Vacios", JOptionPane.WARNING_MESSAGE);
        } else if (campoNombre.getText().isEmpty()) {
            JOptionPane.showMessageDialog(null, "el campo nombre del Puesto esta vacio", "Campos Vacios", JOptionPane.WARNING_MESSAGE);
        } else {
            try {
                mb.conectar();
                ManejadorPuesto.con = (Connection) mb.getConexion();

                if (mp.getPuesto(campoCodigo.getText()) != null) {
                    JOptionPane.showMessageDialog(null, "Este puesto ya esta registrado \n Intente Nuevamente", "error", JOptionPane.ERROR_MESSAGE);
                } else {
                    pu = new Puesto();
                    String id = (campoCodigo.getText());
                    pu.setCodigoPuesto(id);
                    String idZona = comboZona.getSelectedItem().toString();
                    pu.setIdZona(idZona);
                    pu.setNombrePuesto(campoNombre.getText());
                    String Barrio = comboBarrio.getSelectedItem().toString();
                    int idd = barrio.get(Barrio);
                    pu.setIdbarrio(String.valueOf(idd));

                    pu.setHombres(campoMujeres.getText());
                    pu.setMujeres(campoHombres.getText());

                    pu.setCapacidadVotos(total2);

                    pu.setDireccion(areaDireccion.getText());
                    pu.setMesas(campoMesas.getText());
                    ManejadorPuesto.crearPuesto(pu);
                    JOptionPane.showMessageDialog(null, " Puesto Registrado exitosamente!", "Informacion", JOptionPane.INFORMATION_MESSAGE);
                    limpiar();
                    campoCodigo.requestFocus();
                }
            } catch (Exception ex) {
                Logger.getLogger(RegistrarPuesto.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }//GEN-LAST:event_botonGuardarActionPerformed

    private void comboDepartamentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboDepartamentoActionPerformed
        // TODO add your handling code here:
        textDep.setText("");
        String id = comboDepartamento.getSelectedItem().toString();
        int indice = comboDepartamento.getSelectedIndex();
        if (indice != 0) {
            Integer IdDepartamento = departamentos.get(id);
            listaraMunicipios(String.valueOf(IdDepartamento));
            comboMunicipios.setEnabled(true);
//        comboZona.setEnabled(true);
        } else {
            // JOptionPane.showMessageDialog(null, "Seleccione un departamento primero");
            textDep.setText("Seleccione un departamento ");
            comboZona.removeAllItems();
            comboMunicipios.removeAllItems();
//          comboZona.setEnabled(false);
            comboMunicipios.setEnabled(false);

        }

    }//GEN-LAST:event_comboDepartamentoActionPerformed

    private void comboMunicipiosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboMunicipiosActionPerformed
        // TODO add your handling code here:
        listaraZonas();
    }//GEN-LAST:event_comboMunicipiosActionPerformed

    private void comboBarrioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboBarrioActionPerformed
        // TODO add your handling code here:
        listaraLocalidad();
    }//GEN-LAST:event_comboBarrioActionPerformed

    private void campoMujeresKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoMujeresKeyReleased
        // TODO add your handling code here:
        suma();
    }//GEN-LAST:event_campoMujeresKeyReleased

    private void campoHombresKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoHombresKeyReleased
        // TODO add your handling code here:
        suma();
    }//GEN-LAST:event_campoHombresKeyReleased

    private void limpiar() {
        campoNombre.setText("");
        campoCodigo.setText("");
        campoMujeres.setText("");
        campoHombres.setText("");
        campoTotal.setText("");
        areaDireccion.setText("");
        campoMesas.setText("");
        comboBarrio.setSelectedIndex(0);
        comboDepartamento.setSelectedIndex(0);
        campoLocalidad.setText("");
        ucdg.setText("");

    }

    /**
     * @param args the command line arguments
    
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    RegistrarPuesto dialog = new RegistrarPuesto(new javax.swing.JFrame(), true);
    dialog.addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent e) {
    System.exit(0);
    }
    });
    dialog.setVisible(true);
    }
    });
    }*/
    public void listaraDepartamento() {
        ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
        departamentos = new HashMap<String, Integer>();
        try {
            mbd.conectar();
            ManejadorDepartamentos.con = (Connection) mbd.getConexion();
            comboDepartamento.removeAllItems();

            List listarDepartamento = null;
            listarDepartamento = ManejadorDepartamentos.listarDepartamentos();
            Iterator<Departamentos> iter = listarDepartamento.iterator();
            Departamentos dep = null;
            comboDepartamento.addItem("--Seleccione un departamento---");
            while (iter.hasNext()) {
                dep = iter.next();
                int codigoDepartamento = Integer.parseInt(dep.getCodigoDepartamento());
                comboDepartamento.addItem(dep.getNombre());
                departamentos.put(dep.getNombre(), codigoDepartamento);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    } // fin de listar departamentos

    public void listaraBarrios() {
        ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
        barrio = new HashMap<String, Integer>();
        try {
            mbd.conectar();
            ManejadorLugar.con = (Connection) mbd.getConexion();
            comboBarrio.removeAllItems();

            List listarBarrio = null;
            listarBarrio = ManejadorLugar.listarBarrios();
            Iterator<Barrio> iter = listarBarrio.iterator();
            Barrio bar = null;
            comboBarrio.addItem("-- Seleccione un Barrio --");
            while (iter.hasNext()) {
                bar = iter.next();
                int idBarrio = Integer.parseInt(bar.getIdBarrio());
                comboBarrio.addItem(bar.getNombre());
                barrio.put(bar.getNombre(), idBarrio);
            }
        } catch (Exception ex) {
            Logger.getLogger(RegistrarPuesto.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void listaraMunicipios(String idDepartamentos) {
        ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
        municipios = new HashMap<String, Integer>();
        try {
            mbd.conectar();
            ManejadorMunicipios.con = (Connection) mbd.getConexion();
            comboMunicipios.removeAllItems();
            List listarMunicipios = null;
            listarMunicipios = ManejadorMunicipios.listarMunicipios(idDepartamentos);
            Iterator<Municipios> iter = listarMunicipios.iterator();
            Municipios mun = null;
            while (iter.hasNext()) {
                mun = iter.next();
                int codigoMunicipio = Integer.parseInt(mun.getCodigoMunicipio());
                comboMunicipios.addItem(mun.getNombre());
                municipios.put(mun.getNombre(), codigoMunicipio);
            }

            comboMunicipios.setSelectedIndex(8);
            comboMunicipios.setEnabled(true);
            listaraZonas();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }// fin del listar Municipios

    public void listaraZonas() {
        ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
        zonas = new HashMap<String, Integer>();
        try {
            mbd.conectar();
            ManejadorZona.con = (Connection) mbd.getConexion();
            comboZona.removeAllItems();
            List listarZonas = null;
            if (comboMunicipios.isEnabled() && comboMunicipios.getItemCount() > 0) {
                String idM = comboMunicipios.getSelectedItem().toString();
                Integer idMu = municipios.get(idM);

                listarZonas = ManejadorZona.listarZonas(String.valueOf(idMu));
                Iterator<Zona> iter = listarZonas.iterator();
                Zona zon = null;
                while (iter.hasNext()) {
                    zon = iter.next();
                    int codigoZona = Integer.parseInt(zon.getCodigoZona());
                    comboZona.addItem(zon.getCodigoZona());
                    zonas.put(zon.getCodigoZona(), codigoZona);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }// fin del listar Municipios

    public void listaraLocalidad() {
        ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
        localidad = new HashMap<String, Integer>();
        String[] datos = new String[2];
        try {
            mbd.conectar();
            ManejadorLugar.con = (Connection) mbd.getConexion();
//             comboLocalidad.removeAllItems();
            List listarLocalidad = null;
            if (comboBarrio.isEnabled() && comboBarrio.getItemCount() > 0) {
                String idB = comboBarrio.getSelectedItem().toString();
                Integer idBa = barrio.get(idB);

                listarLocalidad = ManejadorLugar.listarLocalidad(String.valueOf(idBa));
                datos = ManejadorLugar.getDatosLugar(String.valueOf(idBa));
                Iterator<Localidad> iter = listarLocalidad.iterator();
//           Localidad loc = null;
//               while (iter.hasNext()){
//           loc = iter.next();
//           int codigo = Integer.parseInt(datos[2]);
//           comboLocalidad.addItem(datos[0]);  en el combo se le pone el nombre de este metodo
                campoLocalidad.setText("Localidad " + datos[0]);
                ucdg.setText(datos[1]);
            }
//            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }// fin del listar localidades
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea areaDireccion;
    private javax.swing.JButton botonCancelar;
    private javax.swing.JButton botonGuardar;
    private javax.swing.JTextField campoCodigo;
    private javax.swing.JTextField campoHombres;
    private javax.swing.JTextField campoLocalidad;
    private javax.swing.JTextField campoMesas;
    private javax.swing.JTextField campoMujeres;
    private javax.swing.JTextField campoNombre;
    private javax.swing.JTextField campoTotal;
    private javax.swing.JComboBox comboBarrio;
    private javax.swing.JComboBox comboDepartamento;
    private javax.swing.JComboBox comboMunicipios;
    private javax.swing.JComboBox comboZona;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private org.jdesktop.swingx.JXPanel jXPanel1;
    private org.jdesktop.swingx.JXTaskPaneContainer jXTaskPaneContainer1;
    private javax.swing.JLabel textDep;
    private javax.swing.JTextField ucdg;
    // End of variables declaration//GEN-END:variables
}
